// This sample illustrates how to create an album

function init() {
   var req = opensocial.newDataRequest();
   var params = {};
   params[opensocial.Album.Field.TITLE] = 'album title';

   var album = new opensocial.Album(params);
   var idspec = opensocial.newIdSpec({"userId" : "VIEWER"}); 
   req.add(req.newCreateAlbumRequest(idspec, album), "album");
   req.send(callback);
   debug.say("Request sent. Waiting for reply...");
}

function callback(resp) {
   debug.say("Album reply.");
   if (resp.hadError()) {
      debug.say("*** Error: " + resp.getErrorMessage());
      // ...handle error here...
      return;
   }
   debug.say("Success.");
   var album = resp.get("album").getData();
   debug.say("Album " + album.id + " created.");
};

gadgets.util.registerOnLoadHandler(init);
